<?php
/**
 * @author 	Vu Nhat Lam
 * 			Mail: lamvnd@gmail.com
 * 			Mobile: 0984 52 62 68
 * @version 1.0.0
 */
// ####################### SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);

// #################### DEFINE IMPORTANT CONSTANTS #######################
define('THIS_SCRIPT', 'btinlinemod');

// ########################## REQUIRE BACK-END ###########################
require_once('./global.php');

// #######################################################################
// ######################### START MAIN SCRIPT ###########################
// #######################################################################
if (!can_moderate())
{
	exit("<center><h3>No permission !</h3></center>");
}

if (empty($_REQUEST['torrentid']))
{
	exit("<center><h3>Missing key torrentid !</h3></center>");
}

$torrentid = intval($_REQUEST['torrentid']);
$torrent   = $db->query_first_slave("
	SELECT halfleech, freeleech, doubleseed
	FROM " . TABLE_PREFIX . "torrent
	WHERE torrentid = $torrentid
");

if (empty($torrent))
{
	exit("<center><h3>Invalid torrent !</h3></center>");
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Torrent moderation</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<?php
if (isset($_POST['do']) && $_POST['do'] == 'doupdate')
{
	$updatequery = '';
	if ($_POST['Leech'] == 0)
	{
		$updatequery .= 'freeleech = 0, halfleech = 0,';
	}
	elseif ($_POST['Leech'] == 1)
	{
		$updatequery .= 'freeleech = 1, halfleech = 0,';
	}
	else
	{
		$updatequery .= 'freeleech = 0, halfleech = 1,';
	}

	if ($_POST['doubleseed'])
	{
		$updatequery .= 'doubleseed = 1';
	}
	else
	{
		$updatequery .= 'doubleseed = 0';
	}

	$db->query_write("
		UPDATE " . TABLE_PREFIX . "torrent SET $updatequery WHERE torrentid = $torrentid
	");
?>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
  	<td style="color:#FF0000; text-align: center;"><b>Update is successful</b></td>
  </tr>
  <tr>
  	<td style="text-align: center;">
	  <a href="btinlinemod.php?torrentid=<?php echo $torrentid;?>">Back</a> &nbsp;|&nbsp;
      <a href="javascript:void(0);" onclick="javascript: window.close();">Close</a>
	</td>
  </tr>
</table>
<?php
}
else
{
?>
<form name="BtInlineMod" action="btinlinemod.php?torrentid=<?php echo $torrentid;?>" method="post">
<input type="hidden" name="do" value="doupdate" />
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td>
      <fieldset>
        <legend>Leech</legend>
        <table width="100%" border="0" cellspacing="0">
          <tr>
            <td>
              <input type="radio" id="freeleech" name="Leech" value="1"<?php if ($torrent['freeleech']) {?> checked="checked"<?php }?> />
              <label for="freeleech">Free leech (free download)</label>
            </td>
          </tr>
          <tr>
            <td>
              <input type="radio" id="halfleech" name="Leech" value="2"<?php if ($torrent['halfleech']) {?> checked="checked"<?php }?> />
              <label for="halfleech">X0.5 (-50% download)</label>
            </td>
          </tr>
          <tr>
            <td>
              <input type="radio" id="disableleech" name="Leech" value="0"<?php if (!$torrent['halfleech'] && !$torrent['freeleech']) {?> checked="checked"<?php }?> />
              <label for="disableleech">Unset (Default)</label>
            </td>
          </tr>
        </table>
      </fieldset>
    </td>
  </tr>
  <tr>
    <td>
      <fieldset>
        <legend>Seed</legend>
        <table width="100%" border="0" cellspacing="0">
          <tr>
            <td>
              <input type="radio" id="enabledoubleseed" name="doubleseed" value="1"<?php if ($torrent['doubleseed']) {?> checked="checked"<?php }?> />
              <label for="enabledoubleseed">X2.0 (+100% upload)</label>
            </td>
          </tr>
          <tr>
            <td>
              <input type="radio" id="disabledoubleseed" name="doubleseed" value="0"<?php if (!$torrent['doubleseed']) {?> checked="checked"<?php }?> />
              <label for="disabledoubleseed">Unset (Default)</label>
            </td>
          </tr>
        </table>
      </fieldset>
    </td>
  </tr>
  <tr><td><br /><hr /></td></tr>
  <tr>
    <td align="right">
	  <input type="submit" name="submit" value="Submit" />&nbsp;&nbsp;
	  <input type="button" name="close" value="Close" onclick="javascript: window.close();" />
    </td>
  </tr>
</table>
</form>
</body>
</html>
<?php
}
